/*
 * chapter_19.cpp
 * 特殊工具与技术
 *  Created on: 2020年12月17日
 *      Author: san
 */

#include <functional>
#include <algorithm>

#include "AndQuery.h"
#include "Querybase.h"
#include "Screen.h"
#include "Sales_data.h"
#include "Token.h"

namespace ch19 {

struct Base {
	int i;
	Base(): i(0){}
	~Base() {}
};

struct D: Base{
	int j;
	D(): Base(), j(1) {}
	~D() {};
};

class A { public: A(){} ~A(){}};
class B : public A { public: B(){} ~B(){} };
class C : public B { public: C(){} ~C(){} };

}

void t19_18()
{
	std::vector<std::string> svec {"", "hello", "sad"};
	std::function<bool (const std::string *)> fp = &std::string::empty;  // function<>
	auto fp2 = std::mem_fn(&std::string::empty);  // mem_fn
	auto count = std::count_if(svec.begin(), svec.end(),
			std::bind(&std::string::empty, std::placeholders::_1));
	std::cout << "counts of empty vec: " <<  count << std::endl;
}

void t19_23()
{
	san::Token token(Sales_data("Y0001"));
}

int main()
{
	using ch19::Base;
	using ch19::D;

	D *d = new D;
	Base *b = d;


	if (typeid(*d) == typeid(*d))
	{
		std::cout << "Sueeced!" << std::endl;
		std::cout << "d.name: " << typeid(*d).name() << std::endl;
//		return 0;
	}

	std::cout << "d.name: " << typeid(*d).name() << std::endl;
	std::cerr << "Failture" << std::endl;

	std::cout << "---------------typeid运算符----------------" << std::endl;
	ch19::A *pa = new ch19::C;
	std::cout << typeid(pa).name() << std::endl;

	std::cout << "---------------------成员函数指针---------------" << std::endl;
	Screen sc;

	std::cout << "------------------将成员函数作为可调用对象----------------" << std::endl;
	t19_18();

	std::cout << "------------------嵌套类----------------" << std::endl;
	// 运行chapter_12/15中的对应程序

	std::cout << "--------------共用体union----------------" << std::endl;
	int i = 10;
	int j = std::move(i);
	std::cout << i  << j << std::endl;
	t19_23();

	std::cout << "------------------------局部类---------------------" << std::endl;


	delete d;
	return 0;
}



